Imports System.Configuration
Imports System.Net.NetworkInformation
Imports System.Collections.Specialized
Imports System.Data
Imports System.Web
Imports System.Web.SessionState
Imports Objects.EmployeeInfo
Imports ConnectionServer
Imports CObject
Imports System.Data.SqlClient
Imports System.Diagnostics
Imports System.Web.Mail
Imports System.IO
Imports Objects.Security.Cryptography
Imports System.DirectoryServices

Public Class cGlobal
    Inherits System.Web.HttpApplication
   
#Region " Component Designer Generated Code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    End Sub

#End Region
    '''
    Public Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
    End Sub

    Public Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires upon attempting to authenticate the use
    End Sub

    Public Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Dim loException As Exception = Nothing
        Try
            If Not Server.GetLastError Is Nothing Then
                loException = Server.GetLastError.GetBaseException
                WriteException(loException)
            Else
                Exit Sub
            End If
        Catch ex As Exception
            loException = ex
            WriteException(loException)
        End Try

    End Sub
    Private Sub WriteException(ByVal poEx As Exception)
        Dim loCrypt As Encryption = New Encryption
        Dim Message As String
        Dim lcookie As HttpCookie = New HttpCookie("ErrorID")

        Dim lsGuid As String = Guid.NewGuid().ToString
        lcookie.Values.Add("ErrorID", lsGuid)
        Response.Cookies.Set(lcookie)

        Message = "Url " & Request.Path & " Error: " & poEx.Message & vbCrLf & "Stack:" & poEx.StackTrace
        Message += "Client IP:" & Request.UserHostAddress & vbCrLf
        Message += "Server Name:" & My.Computer.Name
        Dim Log As EventLog = New EventLog
        If Not EventLog.SourceExists("InfoWeb") Then
            EventLog.CreateEventSource("InfoWeb", "Application")
        End If

        Log.Source = "InfoWeb"

        EventLog.WriteEntry("InfoWeb", lsGuid & "~" & Message, EventLogEntryType.Error)
    End Sub

End Class



